package com.chenyue.cm.user.controller;


import com.chenyue.cm.base.aop.Log;
import com.chenyue.cm.base.bean.PageVo;
import com.chenyue.cm.base.bean.Pageable;
import com.chenyue.cm.bean.Success;
import com.chenyue.cm.common.utils.RequestUtil;
import com.chenyue.cm.user.service.JdOrderCommentService;
import com.chenyue.cm.user.domain.JdOrderComment;
import com.chenyue.cm.user.domain.JdOrderCommentExample;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
* @author chenyue-cm
* @date 2024-02-29
*/
@RestController
@RequestMapping("/jdOrderComment")
public class JdOrderCommentController {

    private final JdOrderCommentService jdOrderCommentService;

    public JdOrderCommentController(JdOrderCommentService jdOrderCommentService) {
        this.jdOrderCommentService = jdOrderCommentService;
    }

    @RequestMapping("/getList")
    public Success getList(HttpServletRequest request) {
        Pageable pageInfo = RequestUtil.getPageable(request);
		PageVo<JdOrderComment>  result  = jdOrderCommentService.getPageBean(pageInfo, JdOrderComment.class);
		return Success.success(result);
    }

    /**
     * @param vo 插入实体
     *
     * @return Success
     */
    @Log
    @RequestMapping("/save")
    public Success save(JdOrderComment vo) {
        boolean success = jdOrderCommentService.save(vo);
        return success ? Success.success() : Success.error();
    }

    /**
    * @param vo 修改实体
    * @param request id
    *
    * @return Success
    */
   @Log
   @RequestMapping("/edit")
   public Success edit(JdOrderComment vo, HttpServletRequest request) {
       String id = request.getParameter("id");
        if (StringUtils.isNotBlank(id)) {
            int success = jdOrderCommentService.getBaseMapper().updateById(vo);
            return success > 0 ? Success.success() : Success.error();
        } else {
          return Success.error("id不能为空");
        }
    }

    /**
     *
     * @param id 主键
     *
     * @return Success
     */
    @Log
    @RequestMapping("/delete/{id}")
    public Success deleteByPrimaryKey(@PathVariable("id") Integer id) {
        boolean success = jdOrderCommentService.removeById(id);
        return success ? Success.success() : Success.error();
    }

 	/**
	 * 【API】----  删除多个数据
     *
	 * @return Success
	 */
    @Log
    @RequestMapping("/delete")
	public Success delete(String ids) {
        String[] idStrings = ids.split(",");
        for (String idString : idStrings) {
            int success = jdOrderCommentService.deleteByPrimaryKey(idString);
            if (success == 0) {
                return Success.error();
            }
        }
        return Success.success();
	}

}
